<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta charset='utf-8' />
	<title>国网云盘系统</title>
	<style>
		.cursers{cursor:pointer}
	</style>
</head>
<body style='background:#ddd;padding:0px;margin:0px;padding-left:10px'>
	<div style='padding:10px;color:blue;font-size:12px'>
		<span onclick='_jumpShareAll()'>全部共享</span>　
		<span onclick='location.replace("main.html")'>文件管理</span>　
	</div>
	<h1 style='text-align:center'>我的共享</h1>

	<div style='padding-left:38px'>
		<input type="text" placeholder='输入文件名' id='searchInp' />
		<button id='searchBtn'>搜索</button>
	</div>

	<div id='fileList' style='margin:30px auto'>
		<div style='border:0px solid;padding:5px 0'>
			<label><div style='border:0px solid;width:40px;height:35px;float:left;padding-top:7px'><input type="checkbox" /></div></label>
			<div style='float:left'><img src="../public/img.png" style='height:35px;width:35px' /></div>
			<div style='float:left'>　　
				<span style='line-height:35px'>aaa</span>　　
				<span style='line-height:35px'>47.57KB</span>　　
				<button>下载</button>　
				<button>删除共享</button>
			</div>
			<div style='clear:both'></div>
		</div>
	</div>



	<div style='margin:30px auto' id='selectBtnArea'>
		<label><div style='border:0px solid;width:40px;height:35px;float:left;padding-top:7px'></div></label>
		<button id='selectAll'>全选</button>
		<button id='selectRev'>反选</button>
		<button id='selectShare'>删除选中</button>
	</div>


</body>
</html>
<script src='../public/jquery1.1.js'></script>
<script src='../public/fun.js'></script>
<script>
var dirList = '';

_checkExit();	//检测账号异常强制退出

//记录搜索值
if(sessionStorage.shareMeSearch){
	$('#searchInp').val(sessionStorage.shareMeSearch);
}

$(function(){
	_getMeShareList();

	Fpage(1,2,function(p){
		//MainGoods_Pnow = p;
		//MainGoods_GetGoodsList();
	},1,1,'#fpage');


 	//搜索
 	$('#searchBtn').click(function(){
 		var search = m_trim($('#searchInp').val());
 		sessionStorage.shareMeSearch = search;
 		location.reload();
 	});

	//全选
	$('#selectAll').click(function(){
		$('input[type=checkbox]').each(function(i,v){
			v.checked = true;
		});
	});
	//反选
	$('#selectRev').click(function(){
		$('input[type=checkbox]').each(function(i,v){
			v.checked = v.checked?false:true;
		});
	});

	//删除选中文件
	$('#selectShare').click(function(){
		if(!confirm('确认删除选中？')){
			return;
		}
		var arr = [];
		$('input[type=checkbox]').each(function(i,v){
			if(v.checked){
				arr.push(v.value);
			}
		});
		if(arr.length < 1){
			A('请选择文件！');
			return;
		}
		var idStr = JSON.stringify(arr);
		var data = {
			type:'selectShare',
			idStr:idStr
		}
		AjaxBefore(data,function(res){
			var tmp = _checkJsonFormat(res); //检测JSON格式
			if(tmp.stat == 'ok'){
				_clearSessData();
				A('操作成功！');
			}else{
				if(tmp.stat == 'err3'){
					A('请选择文件！');
				}else{
					A('操作异常！');
				}
			}
			location.reload();
		});
	});

});	

//获取我的共享文件列表
function _getMeShareList(){
	var view = 0;
	if(sessionStorage.shareMeList){
		if(view)A('getMeShareList sess');
		_parseList(JSON.parse(sessionStorage.shareMeList));
		return;
	}
	var cachePath = '../cache/share_me/' + sessionStorage.account;
	Ajax({},function(cache){
		if(!cache || !/^{.*}$/.test(cache)){
			var data = {
				type:'getMeShareList'
			}
			AjaxBefore(data,function(res){
				if(view)A('getMeShareList after');
				var tmp = _checkJsonFormat(res); //检测JSON格式
				_parseList(tmp.data);
				sessionStorage.shareMeList = JSON.stringify(tmp.data);
			});
		}else{
			if(view)A('getMeShareList cache');
			var tmp_cache = JSON.parse(cache);
			_parseList(tmp_cache.data);
			sessionStorage.shareMeList = JSON.stringify(tmp_cache.data);
		}
	},cachePath,1);




}


function _parseList(res){
	if(typeof(res) != 'object' || res.length < 0){
		return;
	}
	dirList = res;	//将目录列表记录到页面变量中
	var str_file = '';
	if(sessionStorage.shareMeSearch){		//有搜索值
		for(var i=0;i<res.length;i++){
			var p = eval('/'+sessionStorage.shareMeSearch+'/');
			if(p.test(res[i].fname)){
				var fileShow = true;
				var size = _getSize(res[i].size);
				var ctime = StampToYmd(parseFloat(res[i].ctime)*1000);
				str_file += "<div style='border:0px solid;padding:5px 0'><div style='border:0px solid;width:40px;height:35px;float:left;padding-top:7px'></div><div style='float:left'><label><input type='checkbox' value='"+res[i].id+"'  /><img src='../public/file.png' style='height:35px;width:35px' align='top'/></label>　　<span style='line-height:35px'>" + res[i].fname + "</span></label>　　<span style='font-size:12px;color:#88a'>" + size + "</span>　<span style='font-size:12px;color:#88f'>" + ctime + "</span>　<button onclick=_download('"+res[i].path+"','"+res[i].fname+"')>下载</button>　<button onclick=_shareFile("+ res[i].id +",1)>删除共享</button></div><div style='clear:both'></div></div>";
			}
		}
		$('#fileList').html(str_file);
	}else{
		for(var i=0;i<res.length;i++){
			var fileShow = true;
			var size = _getSize(res[i].size);
			var ctime = StampToYmd(parseFloat(res[i].ctime)*1000);
			str_file += "<div style='border:0px solid;padding:5px 0'><div style='border:0px solid;width:40px;height:35px;float:left;padding-top:7px'></div><div style='float:left'><label><input type='checkbox' value='"+res[i].id+"' /><img src='../public/file.png' style='height:35px;width:35px' align='top'/></label>　　<span style='line-height:35px'>" + res[i].fname + "</span></label>　　<span style='font-size:12px;color:#88a'>" + size + "</span>　<span style='font-size:12px;color:#88f'>" + ctime + "</span>　<button onclick=_download('"+res[i].path+"','"+res[i].fname+"')>下载</button>　<button onclick=_shareFile("+ res[i].id +",1)>删除共享</button></div><div style='clear:both'></div></div>";
		}
		$('#fileList').html(str_file);
	}
	if(!fileShow){
		$('#selectBtnArea').hide();
	}

}
</script>